package com.yanqu.road.server.cmd.activity.goldautumn;

import com.yanqu.road.entity.activity.goldautumn.GoldAutumnConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.GoldAutumnProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.goldautumn.GoldAutumnModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.goldautumn.GoldAutumnMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = GoldAutumnProto.GoldAutumnMoveReqMsg.class, respMsg = GoldAutumnProto.GoldAutumnMoveRespMsg.class)
@Cmd(code = Protocol.S_GOLD_AUTUMN_MOVE, desc = "移动")
public class GoldAutumnMoveCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        // 没有活动
        GoldAutumnConfig config = GoldAutumnMgr.getConfig();
        if (config == null || !ActivityMgr.activityInTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }
        GoldAutumnProto.GoldAutumnMoveReqMsg reqMsg = GoldAutumnProto.GoldAutumnMoveReqMsg.parseFrom(packet.getBytes());
        if(reqMsg.getStep() < 0 || reqMsg.getStep() > 4){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }
        ret = player.getModule(GoldAutumnModule.class).move(reqMsg.getStep());

    }

    @Override
    public void sendData(GamePlayer player) {

        if(ret != 0){
            player.sendPacket(Protocol.U_GOLD_AUTUMN_MOVE, GoldAutumnProto.GoldAutumnMoveRespMsg.newBuilder().setRet(ret));
        }

    }
}
